package com.ccs.functions;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Logout {

	public void admin(WebDriver driver) throws Exception {
		
		WebDriverWait wait = new WebDriverWait(driver,30);
	    wait.until(
	        ExpectedConditions.elementToBeClickable(
	             By.xpath("//a[contains(.,'Logout')]")));
		driver.findElement(By.xpath("//a[contains(.,'Logout')]")).click();

		try{
			driver.findElement(By.xpath("//input[@value='LOGIN']"));
			System.out.println("Logout successful!");
		}catch(Exception e){
			System.out.println("Logout failed.");
		}
		
	}
	
	public void hcs(WebDriver driver) throws Exception {
		
		try{
			driver.findElement(By.xpath("//span[@class='ui-icon ui-icon-closethick']")).click();
		}catch(Exception e){}
		
		try{
			driver.findElement(By.xpath("//input[@id='popup_ok']")).click();
		}catch(Exception e){}
		
		WebDriverWait wait = new WebDriverWait(driver,30);
		wait.until(
		    ExpectedConditions.elementToBeClickable(
		        By.xpath("//a[contains(.,'Logout')]")));
		driver.findElement(By.xpath("//a[contains(.,'Logout')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		try{
			driver.findElement(By.xpath("//input[@class='btnLogin']"));
			System.out.println("Logout successful!");
		}catch(Exception e){
			System.out.println("Logout failed.");
		}
		
	}
	
	public void app(WebDriver driver) throws Exception {
		
		WebDriverWait wait = new WebDriverWait(driver,30);
	    wait.until(
	        ExpectedConditions.elementToBeClickable(
	             By.xpath("//a[contains(.,'Logout')]")));
		driver.findElement(By.xpath("//a[contains(.,'Logout')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		try{
			driver.findElement(By.xpath("//a[contains(.,'LOG IN')]"));			
			System.out.println("Logout successful!");
		}catch(Exception e){
			System.out.println("Logout failed.");
		}
		
	}
	
}
